#include "LabelDistributionTextWriter.h"

LabelDistributionTextWriter::LabelDistributionTextWriter(std::string &sOutputFileName)
{
	m_fOutput.open(sOutputFileName.c_str());
	if (!m_fOutput.is_open())
		abort();
}

LabelDistributionTextWriter::~LabelDistributionTextWriter()
{
	if (m_fOutput.is_open())
	{
		m_fOutput.flush();
		m_fOutput.close();
	}
}

int LabelDistributionTextWriter::Write(Node *key, ListLabel *val)
{
	if (!m_fOutput.is_open())
		return 0;

	m_fOutput << key->Id << "\t";
	
	for (ListLabel::iterator itLabel(val->begin()), itLabelEnd(val->end());
		itLabel != itLabelEnd; itLabel++)
	{
		m_fOutput << (*itLabel)->data << "\t" << (*itLabel)->weight << "\t";
	}
	m_fOutput << std::endl;

	return 1;
}

